package com.example.cloud.runner;

import com.example.cloud.service.basic.config.AbnormalTypeService;
import com.example.cloud.service.basic.config.InboundTypeService;
import com.example.cloud.service.basic.config.InventoryWarningService;
import com.example.cloud.service.basic.config.OutboundTypeService;
import com.example.cloud.service.basic.config.ProcessTypeService;
import com.example.cloud.service.basic.config.ProjectTypeService;
import com.example.cloud.service.basic.config.RemindConfigService;
import com.example.cloud.service.basic.config.SupplierService;
import com.example.cloud.service.basic.config.UnitService;
import com.example.cloud.service.basic.info.*;
import com.example.cloud.service.system.AccountService;
import com.example.cloud.service.system.DepartmentService;
import com.example.cloud.service.system.MenuService;
import com.example.cloud.service.system.OrganService;
import com.example.cloud.service.system.RoleService;
import com.example.cloud.service.system.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * Created by wangtao on 2018/3/4.
 */
@Component
public class CommandLineRunnerImpl implements CommandLineRunner {

    private static final Logger logger = Logger.getLogger(CommandLineRunnerImpl.class);

    @Autowired
    private AccountService accountService;

    @Autowired
    private UserService userService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private RoleService roleService;

    @Autowired
    private MenuService menuService;

    @Autowired
    private OrganService organService;

    @Autowired
    private AssetsService assetsService;

    @Autowired
    private BrandService brandService;

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private ComplaintsReasonService complaintsReasonService;

    @Autowired
    private DiseasesService diseasesService;

    @Autowired
    private ProjectService projectService;

    @Autowired
    private EquipmentService equipmentService;

    @Autowired
    private MemberLevelService memberLevelService;

    @Autowired
    private OfficeSuppliesService officeSuppliesService;

    @Autowired
    private ProjectTypeService projectTypeService;

    @Autowired
    private ProductService productService;

    @Autowired
    private CourseService courseService;

    @Autowired
    private CourseDetailsService courseDetailsService;

    @Autowired
    private ServiceProjectService serviceProjectService;

    @Autowired
    private SuggestService suggestService;

    @Autowired
    private SuppliesService suppliesService;

    @Autowired
    private SurgicalProjectService surgicalProjectService;

    @Autowired
    private UnitService unitService;

    @Autowired
    private SupplierService supplierService;

    @Autowired
    private AbnormalTypeService abnormalTypeService;

    @Autowired
    private ProcessTypeService processTypeService;

    @Autowired
    private InboundTypeService inboundTypeService;

    @Autowired
    private OutboundTypeService outboundTypeService;

    @Autowired
    private InventoryWarningService inventoryWarningService;

    @Autowired
    private RemindConfigService remindConfigService;

    @Autowired
    private HomeProjectService homeProjectService;

    @Override
    public void run(String... args) throws Exception {
        /**
         * 系统管理
         */
        logger.info("同步账户缓存开始");
        Long startTime = System.currentTimeMillis();
        accountService.loadCache();
        Long endTime = System.currentTimeMillis();
        logger.info("同步账户缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步用户缓存开始");
        startTime = System.currentTimeMillis();
        userService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步用户缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步部门缓存开始");
        startTime = System.currentTimeMillis();
        departmentService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步部门缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步角色缓存开始");
        startTime = System.currentTimeMillis();
        roleService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步角色缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步菜单缓存开始");
        startTime = System.currentTimeMillis();
        menuService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步菜单缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步组织机构缓存开始");
        startTime = System.currentTimeMillis();
        organService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步组织机构缓存耗时：" + (endTime - startTime) + "ms");
        /**
         * 基础资料
         */
        // ---------------------------
        logger.info("同步医师建议缓存开始");
        startTime = System.currentTimeMillis();
        suggestService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步医师建议缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步医药产品缓存开始");
        startTime = System.currentTimeMillis();
        productService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步医药产品缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步病种缓存开始");
        startTime = System.currentTimeMillis();
        diseasesService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步病种缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步治疗项目缓存开始");
        startTime = System.currentTimeMillis();
        projectService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步治疗项目缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步治疗项目类型缓存开始");
        startTime = System.currentTimeMillis();
        projectTypeService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步治疗项目类型缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步外科项目缓存开始");
        startTime = System.currentTimeMillis();
        surgicalProjectService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步外科项目缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步医疗耗材缓存开始");
        startTime = System.currentTimeMillis();
        suppliesService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步医疗耗材缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步固定资产缓存开始");
        startTime = System.currentTimeMillis();
        assetsService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步固定资产缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步办公用品缓存开始");
        startTime = System.currentTimeMillis();
        officeSuppliesService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步办公用品缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步医疗设备缓存开始");
        startTime = System.currentTimeMillis();
        equipmentService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步医疗设备缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步服务项目缓存开始");
        startTime = System.currentTimeMillis();
        serviceProjectService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步服务项目缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步投诉原因缓存开始");
        startTime = System.currentTimeMillis();
        complaintsReasonService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步投诉原因缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步会员等级缓存开始");
        startTime = System.currentTimeMillis();
        memberLevelService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步会员等级缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步品牌缓存开始");
        startTime = System.currentTimeMillis();
        brandService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步品牌缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步品类缓存开始");
        startTime = System.currentTimeMillis();
        categoryService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步品类缓存耗时：" + (endTime - startTime) + "ms");
        /**
         * 基础配置
         */
        logger.info("同步计量单位开始");
        startTime = System.currentTimeMillis();
        unitService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步计量单位缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步供应商缓存开始");
        startTime = System.currentTimeMillis();
        supplierService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步供应商缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步异常类型缓存开始");
        startTime = System.currentTimeMillis();
        abnormalTypeService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步异常类型缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步处理类型缓存开始");
        startTime = System.currentTimeMillis();
        processTypeService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步处理类型缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步入库类型缓存开始");
        startTime = System.currentTimeMillis();
        inboundTypeService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步入库类型缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步出库类型缓存开始");
        startTime = System.currentTimeMillis();
        outboundTypeService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步出库类型缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步库存预警配置缓存开始");
        startTime = System.currentTimeMillis();
        inventoryWarningService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步库存预警缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步消息提醒配置缓存开始");
        startTime = System.currentTimeMillis();
        remindConfigService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步消息提醒配置缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步病房项目缓存开始");
        startTime = System.currentTimeMillis();
        homeProjectService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步病房项目缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步疗程缓存开始");
        startTime = System.currentTimeMillis();
        courseService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步疗程缓存耗时：" + (endTime - startTime) + "ms");
        // ---------------------------
        logger.info("同步疗程明细缓存开始");
        startTime = System.currentTimeMillis();
        courseDetailsService.loadCache();
        endTime = System.currentTimeMillis();
        logger.info("同步疗程明细缓存耗时：" + (endTime - startTime) + "ms");
    }
}
